<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title th:text="${pageTitle} ?: '网站导航'">网站导航</title>
    <link rel="stylesheet" href="/css/style.css">
    <style>
        /* 网站导航页面样式 */
        body {
            background-color: #2d2d2d;
            color: #fff;
            font-family: 'Microsoft YaHei', Arial, sans-serif;
            margin: 0;
            padding: 0;
            background-image: url('');
            background-size: cover;
            background-position: center center;
            background-attachment: fixed;
            background-repeat: no-repeat;
        }
        
        .container {
            max-width: 1200px;
            margin: 0 auto;
            padding: 20px;
            background-color: transparent;
            border-radius: 15px;
            box-shadow: none;
            backdrop-filter: none;
            border: none;
        }
        
        .page-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 30px;
            padding-bottom: 15px;
            border-bottom: 1px solid rgba(255, 255, 255, 0.2);
        }
        
        .page-title {
            font-size: 28px;
            margin: 0;
            color: #4ef2f8;
            text-shadow: 0 0 15px rgba(78, 242, 248, 0.7);
            font-weight: bold;
        }
        
        .weblinks-container {
            width: 100%;
            margin-top: 20px;
        }
        
        .weblinks-grid {
            display: flex;
            flex-wrap: wrap;
            gap: 20px;
            margin-top: 20px;
            max-width: 1200px;
        }
        
        .category-section {
            display: flex;
            flex-wrap: wrap;
            gap: 20px;
            width: 100%;
        }
        
        .category-all {
            display: flex !important;
            flex-wrap: wrap;
            gap: 20px;
        }
        
        .category-uncategorized,
        [class^="category-"] {
            display: flex;
            flex-wrap: wrap;
            gap: 20px;
        }
        
        .weblink-item {
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            width: 120px;
            height: 140px;
            padding: 15px;
            background-color: transparent;
            border-radius: 10px;
            box-shadow: none;
            text-decoration: none;
            color: #fff;
            transition: all 0.3s ease;
            text-align: center;
            backdrop-filter: none;
            border: 1px solid rgba(255, 255, 255, 0.1);
        }
        
        .weblink-item:hover {
            transform: translateY(-3px);
            background-color: rgba(78, 242, 248, 0.1);
            box-shadow: 0 0 15px rgba(78, 242, 248, 0.3);
            border: 1px solid rgba(78, 242, 248, 0.2);
        }
        
        .weblink-icon {
            font-size: 32px;
            margin-bottom: 12px;
            display: flex;
            align-items: center;
            justify-content: center;
            width: 60px;
            height: 60px;
            border-radius: 50%;
            background-color: rgba(0, 0, 0, 0.2);
            border: 1px solid rgba(255, 255, 255, 0.2);
            overflow: hidden;
        }
        
        .weblink-icon span {
            font-size: 32px;
            color: #4ef2f8;
        }
        
        .weblink-icon img {
            width: 100%;
            height: 100%;
            object-fit: cover;
            border-radius: 50%;
        }
        
        .weblink-title {
            font-size: 14px;
            font-weight: normal;
            margin-top: 10px;
            margin-bottom: 0;
            color: #fff;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
            width: 100%;
        }
        
        .weblink-description {
            font-size: 12px;
            color: #aaa;
            margin-top: 5px;
            display: -webkit-box;
            -webkit-line-clamp: 2;
            -webkit-box-orient: vertical;
            overflow: hidden;
        }
        
        /* 分类导航栏 - 透明水平排列 */
        .category-bar {
            display: flex;
            flex-wrap: wrap;
            gap: 10px;
            margin-bottom: 20px;
            padding: 15px 20px;
            background: transparent;
            backdrop-filter: none;
            border-radius: 8px;
            border: none;
        }
        
        .category-item {
            display: inline-block;
            padding: 6px 15px;
            background: rgba(0, 0, 0, 0.4);
            border: 1px solid rgba(255, 255, 255, 0.2);
            border-radius: 20px;
            color: #fff;
            text-decoration: none;
            transition: all 0.3s ease;
            font-size: 14px;
            cursor: pointer;
            backdrop-filter: none;
        }
        
        .category-item:hover {
            background: rgba(78, 242, 248, 0.3);
            box-shadow: 0 0 10px rgba(78, 242, 248, 0.3);
            transform: translateY(-2px);
            border-color: transparent;
        }
        
        .category-item.active {
            background: rgba(78, 242, 248, 0.4);
            border-color: transparent;
            box-shadow: 0 0 15px rgba(78, 242, 248, 0.4);
            color: #fff;
        }
        
        /* 页眉和页脚透明化 */
        .main-header, .main-footer {
            background: transparent;
            backdrop-filter: none;
            -webkit-backdrop-filter: none;
            border: none;
        }
        
        .main-header nav ul {
            display: flex;
            list-style: none;
            padding: 0;
            margin: 0;
        }
        
        .main-header nav ul li {
            margin-right: 15px;
        }
        
        .main-header nav ul li a {
            color: rgba(240, 250, 255, 0.95);
            text-decoration: none;
            padding: 5px 10px;
            border-radius: 5px;
            transition: background-color 0.2s;
            text-shadow: 0 1px 2px rgba(0, 0, 0, 0.7);
        }
        
        .main-header nav ul li a:hover {
            background-color: rgba(78, 242, 248, 0.2);
        }
        
        @media (max-width: 768px) {
            .weblinks-grid {
                grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
                gap: 15px;
            }
            
            .weblink-icon {
                font-size: 30px;
                width: 50px;
                height: 50px;
                line-height: 50px;
            }
        }
        
        @media (max-width: 480px) {
            .weblinks-grid {
                grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
                gap: 10px;
            }
            
            .container {
                padding: 10px;
            }
            
            .weblink-title {
                font-size: 12px;
            }
        }
        
        /* 背景覆盖层 */
        .page-overlay {
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: rgba(0, 0, 0, 0.1);
            z-index: -1;
        }
        
        /* 当有背景图片时，为容器添加半透明背景 */
        body.has-bg .container {
            background-color: transparent;
            box-shadow: none;
            border-radius: 15px;
            backdrop-filter: none;
            border: none;
        }
    </style>
</head>
<body th:style="${backgroundImage != '' ? 'background-image: url(' + backgroundImage + ');' : ''}" th:class="${backgroundImage != '' ? 'has-bg' : ''}">
    <!-- 背景覆盖层 -->
    <div class="page-overlay" th:if="${backgroundImage != ''}" th:style="'background-color: rgba(0, 0, 0, ' + ${backgroundOpacity} + ')'"></div>
    
    <!-- 导航栏 -->
    <header class="main-header">
        <div class="container">
            <nav>
                <ul>
                    <li><a href="/">首页</a></li>
                    <li><a href="/weblinks">网站导航</a></li>
                    <li><a href="/danmaku-display">弹幕墙</a></li>
                    <li><a href="/dashboard" th:if="${#authorization.expression('isAuthenticated()')}">控制台</a></li>
                    <li><a href="/login" th:if="${#authorization.expression('!isAuthenticated()')}">登录</a></li>
                    <li><a href="/register" th:if="${#authorization.expression('!isAuthenticated()')}">注册</a></li>
                    <li><a href="/logout" th:if="${#authorization.expression('isAuthenticated()')}">退出</a></li>
                </ul>
            </nav>
        </div>
    </header>

    <div class="container">
        <div class="page-header">
            <h1 class="page-title">网站导航</h1>
        </div>
        
        <!-- 全新设计的分类栏 -->
        <div class="category-bar">
            <div th:each="category : ${linkCategories}" 
                 class="category-item" 
                 th:data-category="${category.id}"
                 th:text="${category.name}">分类名称</div>
        </div>
        
        <!-- 网站链接网格（重新设计） -->
        <div class="weblinks-container">
            <!-- 所有网站链接 -->
            <div class="weblinks-grid" id="all-links">
                <a th:each="link : ${webLinks}" 
                   th:href="${link.url}" 
                   th:data-category="${link.category != null ? link.category.id : 'uncategorized'}"
                   target="_blank" class="weblink-item">
                    <!-- 显示图标 -->
                    <div class="weblink-icon" th:if="${link.icon != null && !link.icon.startsWith('http')}">
                        <span th:text="${link.icon}">🔗</span>
                    </div>
                    <div class="weblink-icon" th:if="${link.icon != null && link.icon.startsWith('http')}">
                        <img th:src="${link.icon}" alt="网站图标">
                    </div>
                    
                    <div class="weblink-title" th:text="${link.title}">网站标题</div>
                </a>
            </div>
            
            <!-- 当没有网站链接时显示的提示 -->
            <div th:if="${webLinks == null || webLinks.isEmpty()}" style="text-align: center; padding: 30px;">
                <p>暂无网站链接。</p>
                <p th:if="${#authorization.expression('hasRole(''ADMIN'')')}">
                    <a href="/dashboard/weblinks/new" style="color: #4ef2f8; text-decoration: none;">
                        添加网站链接
                    </a>
                </p>
            </div>
        </div>
        
        <!-- 全新的分类筛选JavaScript -->
        <script>
            document.addEventListener('DOMContentLoaded', function() {
                // 获取所有分类按钮和链接
                const categoryButtons = document.querySelectorAll('.category-item');
                const linkItems = document.querySelectorAll('.weblink-item');
                
                // 为每个分类按钮添加点击事件
                categoryButtons.forEach(button => {
                    button.addEventListener('click', function() {
                        // 移除所有按钮的active类
                        categoryButtons.forEach(btn => btn.classList.remove('active'));
                        
                        // 为当前点击的按钮添加active类
                        this.classList.add('active');
                        
                        // 获取选中的分类ID
                        const selectedCategory = this.getAttribute('data-category');
                        
                        // 显示或隐藏相应的链接
                        linkItems.forEach(link => {
                            const linkCategory = link.getAttribute('data-category');
                            
                            if (selectedCategory === linkCategory) {
                                link.style.display = 'flex';
                            } else {
                                link.style.display = 'none';
                            }
                        });
                    });
                });
                
                // 页面加载时默认选中第一个分类
                if (categoryButtons.length > 0) {
                    categoryButtons[0].classList.add('active');
                    const firstCategory = categoryButtons[0].getAttribute('data-category');
                    
                    // 显示第一个分类的链接
                    linkItems.forEach(link => {
                        const linkCategory = link.getAttribute('data-category');
                        if (firstCategory === linkCategory) {
                            link.style.display = 'flex';
                        } else {
                            link.style.display = 'none';
                        }
                    });
                }
            });
        </script>
    </div>
</body>
</html> 